#include<stdio.h>
#include<math.h>
int T , M , N , K;
#define MAX_NUM 55
int aField[MAX_NUM][MAX_NUM];
main()
{
	scanf("%d %d %d",&M,&N,&K);
	for(int m = 1; m <= M; m++)
	   for(int n = 1; n <= N; n++)
	      scanf("%d",&aField[m][n]);
	int nTotalPeanuts = 0;
	int nTotalTime = 0;
	int nCuri = 0,nCurj;
	
	while( nTotalTime < K)
	{
		int nMax = 0,nMaxi,nMaxj;
		for(int i = 1; i <= M; i++)
		{
			for(int j = 1; j <= N; j++)
			{
				if(nMax < aField[i][j])
				{
					nMax = aField[i][j];
					nMaxi = i;
					nMaxj = j;
				}
			}
		}
		if( nMax == 0)
		  break;
		if(nCuri == 0)
		  nCurj = nMaxj;
		 
		if( nTotalTime + nMaxi + 1 + abs(nMaxi-nCuri) + abs(nMaxj-nCurj) <= K) 
		{
			nTotalTime += 1 + abs(nMaxi-nCuri) + abs(nMaxj-nCurj);
			nCuri = nMaxi; 
			nCurj = nMaxj; 
			nTotalPeanuts += aField[nMaxi][nMaxj];
			aField[nMaxi][nMaxj] = 0;
		}
		else
		break;
	}
	printf("%d\n",nTotalPeanuts);
	return 0;
}
